package com.xbongbong.paas.elasticsearch.model;

import com.xbongbong.paas.domain.entity.PaasFormSubDataEntity;
import com.xbongbong.paas.elasticsearch.pojo.XbbAggregatedPage;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 魏荣杰
 * @date 2020/9/10 19:46
 * @since
 * @version
 */
public interface PaasFormSubDataEsModel {

    void insert(PaasFormSubDataEntity paasFormSubDataEntity, IndexTypeEnum indexTypeEnum) throws XbbException;

    void insert(PaasFormSubDataEntity paasFormSubDataEntity, IndexTypeEnum indexTypeEnum, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    void insertBatch(List<? extends PaasFormSubDataEntity> paasFormSubDataEntityList, IndexTypeEnum indexTypeEnum) throws XbbException;

    void update(PaasFormSubDataEntity paasFormSubDataEntity, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * 子表单批量更新
     * @param list
     * @param indexTypeEnum
     * @param refreshPolicy
     * @return void
     * @author 吴峰
     * @date 2020/9/22 14:16
     * @throws XbbException
     */
    void updateBatch(List<UpdateDataEntity> list, IndexTypeEnum indexTypeEnum, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    void deleteBatch(String corpid, List<? extends PaasFormSubDataEntity> entities, IndexTypeEnum indexTypeEnum, WriteRequest.RefreshPolicy refreshPolicy, DelEnum delEnum) throws XbbException;

    /**
     *
     * @param corpid
     * @param idMap
     * @param indexTypeEnum
     * @param refreshPolicy
     * @param delEnum
     * @throws XbbException
     */
    void deleteBatchByIdIn(String corpid, Map<Long, Long> idMap, IndexTypeEnum indexTypeEnum, WriteRequest.RefreshPolicy refreshPolicy, DelEnum delEnum) throws XbbException;
    /**
     * 根据父节点id查询子表单数据
     * @param corpid
     * @param saasMark
     * @param businessType
     * @param formId
     * @param dataIdList
     * @param page
     * @param pageSize
     * @return
     * @throws XbbException
     */
    List<PaasFormSubDataEntity> getSubDataByParentId(String corpid, Integer saasMark, Integer businessType,
                                                     Long formId, Collection<Long> dataIdList, Integer page, Integer pageSize, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * 根据父节点id查询子表单数据
     * @param corpid
     * @param saasMark
     * @param businessType
     * @param formId 查询的目标表单
     * @param dataIdList 对应的
     * @param page
     * @param pageSize
     * @param del
     * @return
     * @throws XbbException
     */
    List<PaasFormSubDataEntity> getSubDataByParentIdAndDel(String corpid, Integer saasMark, Integer businessType,
                                                            Long formId, Collection<Long> dataIdList, Integer page, Integer pageSize, Integer del, IndexTypeEnum indexTypeEnum) throws XbbException;
    /**
     * 根据父节点id查询子表单数据
     * @param corpid
     * @param saasMark
     * @param fieldList 字段
     * @param businessType
     * @param formId 查询的目标表单
     * @param dataIdList 对应的
     * @param page
     * @param pageSize
     * @return
     * @throws XbbException
     */
    List<PaasFormSubDataEntity> getSubDataByParentId(String corpid, Integer saasMark, Integer businessType, List<String> fieldList,
                                                     Long formId, Collection<Long> dataIdList, Integer page, Integer pageSize, IndexTypeEnum indexTypeEnum) throws XbbException;
    /**
     * 获取子表单数据
     * @param boolQueryBuilder
     * @param indexTypeEnum
     * @param fieldList 查询的字段，例子["num_1", "text_1", "subForm_1.text_1"]
     * @param page
     * @param pageSize
     * @param clazz
     * @return java.util.List<T>
     * @author 吴峰
     * @date 2020/10/10 15:13
     * @throws XbbException
     */
    <T> List<T> getSubDataList(BoolQueryBuilder boolQueryBuilder, IndexTypeEnum indexTypeEnum,
                               List<String> fieldList, Integer page, Integer pageSize, Class<T> clazz) throws XbbException;
    /**
     * 子表单批量更新
     * @param list
     * @param indexTypeEnum
     * @param refreshPolicy
     * @return void
     * @author 吴峰
     * @date 2020/10/15 15:51
     * @throws XbbException
     */
    void updateBatchByEntity(List<? extends PaasFormSubDataEntity> list, IndexTypeEnum indexTypeEnum, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 查询子表单数据，可自定义返回实体
     * @param boolQueryBuilder 条件封装
     * @param indexTypeEnum 查询的所有
     * @param fieldList 查询的字段
     * @param page 页数
     * @param pageSize 一页的数量
     * @param clazz 自定义返回的实体
     * @param <T> 泛型
     * @return 实体列表
     * @throws XbbException
     */
    <T> XbbAggregatedPage<T> list(BoolQueryBuilder boolQueryBuilder, IndexTypeEnum indexTypeEnum,
                              List<String> fieldList, Integer page, Integer pageSize, Class<T> clazz) throws XbbException;

}
